package com.zhiyou.app.shop.website.service.impl;

import java.util.List;

import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhiyou.app.shop.common.util.Page;
import com.zhiyou.app.shop.website.dao.IStockInfoDao;
import com.zhiyou.app.shop.website.dao.pojo.StockInfo;
import com.zhiyou.app.shop.website.service.IStockInfoService;

@Service(value="stockInfoService")
public class StockInfoServiceImpl implements IStockInfoService {

	@Autowired
	private IStockInfoDao stockInfoDao;
	
	public void findStockInfo(Page page) {
		StockInfo info = new StockInfo();
		stockInfoDao.findByExample(page, info, Order.desc("periods"));
		
	}

	public void saveStockInfo(StockInfo info) {
		stockInfoDao.save(info);
	}
	
	


	public StockInfo findByPeriods(Integer periods) {
		List<StockInfo> list = stockInfoDao.findByProperty("periods", periods);
		if(list != null && list.size() > 0){
			return list.get(0);
		}
		return null;
	}

	public Integer findMaxPeriods() {
		return stockInfoDao.findMaxPeriods();
	}

	public void update(StockInfo info) {
		stockInfoDao.update(info);
		
	}

}
